import React from 'react';
import { Row, Col } from 'antd';
import { Form, Icon, Input, Button, Checkbox } from 'antd';
import './../../css/pc/login.css';
import axios from '../axios';
const FormItem = Form.Item;


class Login extends React.Component {
    handleSubmit = (e) => {
        e.preventDefault();
        var formData = this.props.form.getFieldsValue();
        var _this = this;
        this.props.form.validateFields((err, values) => {
            if (!err) {
                console.log('Received values of form: ', values);
                console.log(formData.userName);
                console.log(formData.password);
                // fetch("http://localhost:8080/user/login", {
                //     method: "POST",
                //     headers: {
                //         'Content-Type': 'application/json',
                //         'token': "qqq"
                //     },
                //     body: {
                //         "username": formData.userName,
                //         "password": formData.password
                //     }
                // })
                // .then(response => response.json())
                // .then(json => {
                //     console.log(json);
                //     localStorage.setItem("token", json.data);
                //     this.props.history.push('/index');
                // });
                // axios.post('/login', {
                //     username: formData.userName,
                //     password: formData.password
                // })
                // .then(function (res) {
                //     console.log(res.data);
                //     if(res.data.status == 200){
                //         sessionStorage.setItem('token', res.data.data);
                //      //   _this.props.history.push('/index');
                //     }
                    
                // })
                // .catch(function (error) {
                //     console.log(error);
                // });
                axios({
                    method: 'post',
                    url: '/login',
                    params: {
                      username: 'qqq',
                      password: '123'
                    }
                  })
                  .then(function (res) {
                    console.log(res.data);
                    if(res.data.status == 200){
                        sessionStorage.setItem('token', res.data.data);
                        //   _this.props.history.push('/index');
                    }
                    
                })
                .catch(function (error) {
                    console.log(error);
                });

            }
        });
    }
    render() {
        const { getFieldDecorator } = this.props.form;
        return (
            <Row type="flex" justify="center">
                <Col span={6}>
                    <div id="components-form-demo-normal-login">
                        <Form onSubmit={this.handleSubmit} className="login-form">
                            <FormItem>
                                {getFieldDecorator('userName', {
                                    rules: [{ required: true, message: 'Please input your username!' }],
                                })(
                                    <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="Username" />
                                    )}
                            </FormItem>
                            <FormItem>
                                {getFieldDecorator('password', {
                                    rules: [{ required: true, message: 'Please input your Password!' }],
                                })(
                                    <Input prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" placeholder="Password" />
                                    )}
                            </FormItem>
                            <FormItem>
                                {getFieldDecorator('remember', {
                                    valuePropName: 'checked',
                                    initialValue: true,
                                })(
                                    <Checkbox>Remember me</Checkbox>
                                    )}
                                <a className="login-form-forgot" href="">Forgot password</a>
                                <Button type="primary" htmlType="submit" className="login-form-button">
                                    Log in
                            </Button>
                                Or <a href="">register now!</a>
                            </FormItem>
                        </Form>
                    </div>
                </Col>
            </Row>
        )
    }
}
export default Login = Form.create()(Login);